package com.demo.consumer;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.tomcat.util.ExceptionUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * @Description: 消费
 * @author: fanfan
 */
@Component
@Slf4j
public class RiskDataConsumer extends KafkaConsumer<String, String> {

	@Value("${spring.kafka.consumer.group-id}")
	private String groupId;

	@Override
	@KafkaListener(topics = { "test" })
	public void consume(ConsumerRecord<String, String> record) {
		super.consume(record);
	}

	/**
	 * 消费Kafka数据具体实现
	 */
	@Override
	protected void executeRecord(ConsumerRecord<String, String> record) {
		final String key = record.key();
		final String value = record.value();
		final String topic = record.topic();
		// 业务处理
		try {
			log.info("topic:{},key:{},value:{}",topic,key,value);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}
	}

}
